// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import VirtualItem from "../../ui/VirtualItem";
import { VirtualArgs } from "../../ui/VirtualList";

const {ccclass, property} = cc._decorator;

export interface PlateAmountArgs extends VirtualArgs {
    ts_code: string,
    name: string,
    amount: number,
    rate: number,
    maxAmount: number,  
    total: number,  
}

@ccclass
export default class PlateVolumeItem extends VirtualItem<PlateAmountArgs> {

    @property(cc.Label)
    labelName: cc.Label = null;

    @property(cc.Node)
    volume: cc.Node = null;

    @property(cc.Label)
    labelAmount: cc.Label = null;

    @property(cc.Label)
    labelRate: cc.Label = null;

    ts_code: string = '';

    // LIFE-CYCLE CALLBACKS:

    public onRefresh(args: PlateAmountArgs) {
        this.labelName.string = args.name;
        this.ts_code = args.ts_code;
        let amount = Math.ceil(args.amount / 100000000); 
        this.volume.height = args.amount / args.maxAmount * 240;
        if (this.volume.height > 240) {
            this.volume.height = 240;
        }
        let strAmount = '量' + amount + '亿';
        this.labelAmount.string = strAmount;
        this.labelRate.string = '换' + Math.ceil(args.rate * 100) / 100  + '%';
    }

    // update (dt) {}
}
